package com.jq.aution.common;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 统一日志处理切面
 * Created by jiangqi on 2020/8/29
 */
@Aspect
@Component
public class WebLogAspect {
    private static final Logger LOGGER= LoggerFactory.getLogger(WebLogAspect.class);

    @Pointcut("execution(public * com.jq.aution.controller.*.*(..))")
    public void webLog() {
    }

    @Around("webLog()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        LOGGER.info(joinPoint.getTarget().getClass().getName()+"."+joinPoint.getSignature().getName()+"开始执行");
        Object o = null;
        try {
            o=joinPoint.proceed();
        }catch (Exception e){
            LOGGER.error(joinPoint.getTarget().getClass().getName()+"执行出错");
            LOGGER.error(e.getMessage());
        }
        LOGGER.info(joinPoint.getTarget().getClass().getName()+"."+joinPoint.getSignature().getName()+"执行完毕");
        return o;
    }
}
